import math

MAX_TRY = 200
def newton_raphson(start, f, fp):
    x = start

    for _ in range(MAX_TRY):
        x_next = x- f(x)/fp(x)
        if abs(x_next-x)<1e-12:
            break
        x = x_next
    return x

def f(x):
    return x*x-2

def fprime(x):
    return 2*x

if __name__ == "__main__":
    sqrt2 = newton_raphson(1, f, fprime)
    print(sqrt2,math.sqrt(2))
    print(math.sqrt(2) == sqrt2)